package org.digitaldomination.thefinalcountdown;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class Singlecountdown extends Activity implements OnClickListener {

	final DBAdapter db = new DBAdapter(this);
	Globals globals = new Globals(this);
	long value;
	String titletext, countdowntext;
	ImageButton twitterbutton;

	String dbId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.singlecountdown);
		
		dbId = getIntent().getExtras().getString("dbId");
		value = Long.parseLong(dbId);
		
		db.open();
        Cursor c = db.getsinglecount(value);
        if (c.moveToFirst())
        	display(c);
        else
        	Toast.makeText(this, "You triced me!! its nothing here!", Toast.LENGTH_LONG).show();
        	db.close();
        	twitterbutton = (ImageButton) findViewById(R.id.imageButton2);
        	twitterbutton.setOnClickListener(this);
	}
	
	public void display(Cursor c)
    {
    	TextView title = (TextView) findViewById(R.id.title);
    	TextView countdown = (TextView) findViewById(R.id.countdown);
		titletext = c.getString(c.getColumnIndex("title"));
		long count_to = c.getLong(c.getColumnIndex("date_to"));
		long count_from = c.getLong(c.getColumnIndex("date_from"));
		int count_type = c.getInt(c.getColumnIndex("count_type"));
		switch(count_type)
		{
			case 1:
				countdowntext = globals.writetime(count_to);
			break;
			case 2:
				countdowntext = globals.writetime(count_from);
			break;
			case 3:
				countdowntext = globals.writeprogress(count_to, count_from);
			break;
		}
    	title.setText(titletext);
    	countdown.setText(countdowntext);
    }

	public void onClick(View arg0) {
		switch(arg0.getId())
		{
		case R.id.imageButton2:

			break;
		}
		
	}


}
